﻿Imports System.Data.OleDb
Public Class cakeByTags
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack = True Then
            Repeater1.DataBind()
        Else
            cblTags.DataBind()
        End If

        If Request.Params("tag") = Nothing Then
            'No Preloaded Tag
        Else
            'Preloaded Tag so tick
            Dim tag As String = ""
            tag = Request.Params("tag")

            For Each item As ListItem In cblTags.Items
                If item.Text = tag Then
                    item.Selected = True
                End If
            Next

        End If
    End Sub

    Function getpics(ByVal cakeNo As Integer, ByVal picloco As String)

        Dim include As Boolean = True


        'Check if cake has that tag
        For Each item As ListItem In cblTags.Items
            If item.Selected = True Then
                'Check if Cake has that Tag if not then return nothing
                Dim SQL As String = "SELECT * FROM CakeTagsLink WHERE C_FID = @f1 AND CT_FID = @f2"
                Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("CakeConnection").ConnectionString)
                Dim cmd As OleDbCommand = New OleDbCommand(SQL, conn)
                cmd.Parameters.AddWithValue("@f1", cakeNo)
                cmd.Parameters.AddWithValue("@f2", item.Value)
                conn.Open()

                Dim dr As OleDbDataReader = cmd.ExecuteReader()
                dr.Read()
                If dr.HasRows Then
                    'Do nothing
                Else
                    'No Tag
                    include = False
                End If
                dr.Close()
                conn.Close()
                cmd.Dispose()
                conn.Dispose()
            End If
        Next


        If include = True Then
            Return "<a href=details.aspx?cakeNo=" & cakeNo & "> <img src = " & picloco & " width = 100 height = 100></a>"
        Else
            Return ""
        End If


    End Function

End Class